package ihm;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import metier.Equipe;
import metier.Membre;
import dao.DaoGestionProjet;


public class FenetrePrincipale extends JFrame {

	private JPanel contentPane;
	public static JTextField textField;
    public static JPasswordField passwordField;
    Membre unMembre;
    Equipe uneEquipe;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FenetrePrincipale frame = new FenetrePrincipale();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FenetrePrincipale() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 477, 338);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Gestion de projet");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 22));
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(88, 0, 257, 30);
		panel.add(lblNewLabel);
		
		JLabel lblAuthentification = new JLabel("Authentification");
		lblAuthentification.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		lblAuthentification.setBounds(152, 56, 137, 19);
		panel.add(lblAuthentification);
		
		JLabel lblLogin = new JLabel("Login :");
		lblLogin.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
		lblLogin.setBounds(139, 125, 63, 14);
		panel.add(lblLogin);
		
		JLabel lblMotDePasse = new JLabel("Mot de passe :");
		lblMotDePasse.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
		lblMotDePasse.setBounds(96, 150, 93, 14);
		panel.add(lblMotDePasse);
		
		setTextField(new JTextField());
		getTextField().setBounds(199, 122, 86, 20);
		panel.add(getTextField());
		getTextField().setColumns(10);
	
		
		setPasswordField(new JPasswordField());
		getPasswordField().setBounds(199, 147, 86, 20);
		panel.add(getPasswordField());
		
		JButton btnValider = new JButton("Valider");
		btnValider.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				unMembre = DaoGestionProjet.connexion(textField.getText() ,passwordField.getText());
				if (unMembre == null)
					System.out.println("Membre inconnu");
				else
				{
					TestJList2 tjl = new TestJList2(unMembre,uneEquipe);
					
					tjl.setBounds(100,100,751,480);
					tjl.setModal(true);
					tjl.setVisible(true);
					
				
				}
			}
		});
		btnValider.setBounds(336, 214, 91, 23);
		panel.add(btnValider);
		
		JButton btnQuitter = new JButton("Quitter");
		btnQuitter.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				System.exit(0);
			}
		});
		btnQuitter.setBounds(336, 248, 91, 23);
		panel.add(btnQuitter);
	}

	public JTextField getTextField()
	{
		return textField;
	}

	public void setTextField(JTextField textField)
	{
		this.textField = textField;
	}

	public JPasswordField getPasswordField()
	{
		return passwordField;
	}

	public void setPasswordField(JPasswordField passwordField)
	{
		this.passwordField = passwordField;
	}
}
